package cn.iocoder.yudao.module.member.assets.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.member.assets.service.AppMemberDigitalAssetsService;
import cn.iocoder.yudao.module.member.assets.vo.AppBonusOverviewRespVO;
import cn.iocoder.yudao.module.member.assets.vo.AppDigitalAssetsConvertSubmitVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 数字资产")
@RestController
@RequestMapping("/member/digital-assets")
@Validated
public class AppMemberBonusController {
    @Resource
    private AppMemberDigitalAssetsService appMemberDigitalAssetsService;

    @GetMapping("/bonus/overview")
    @Operation(summary = "获得分红概览")
    public CommonResult<AppBonusOverviewRespVO> getBonusOverview() {
        return success(appMemberDigitalAssetsService.getBonusOverview(getLoginUserId()));
    }

    @PostMapping("/bonus/to-money")
    @Operation(summary = "分红兑换零钱")
    public CommonResult<Boolean> doBonusToMoneySubmit(@Valid @RequestBody AppDigitalAssetsConvertSubmitVO submitVO) {
        appMemberDigitalAssetsService.submitBonusToMoney(getLoginUserId(), submitVO.getAmount());
        return success(true);
    }

}